% draws the body of the dog, once every freq steps.
% the figure's resolution and size is fixed.

function seeDog(pathfilename, freq)
   gridSize = 0.01;
   xMin = -.20;
   xMax = 3;
   yMin = -1.5;
   yMax = 1.5;
   
   actions = load(pathfilename);
   
   numSteps = length(actions(:,1));
   x = zeros(1,4);
   y = zeros(1,4);
   xstart = [0.8, 0.8,-0.8,-0.8];
   ystart = [0.6,-0.6, 0.6,-0.6];
   figure; 
   hold on;
   axis([xMin xMax yMin yMax]);
   
   for line=freq:freq:numSteps
      foot = actions(line,1)+1;
      x(foot)=actions(line,2);
      y(foot)=actions(line,3);
      for f=1:4
          if (f ~= foot)
             found = 0;
             linecursor = line;
             while(found==0)
                 linecursor = linecursor-1;
                 if (linecursor<1)
                     break;
                 end
                 if((actions(linecursor,1)+1)==f)
                    found = 1;
                 end
             end
             if (found==0)
                x(f)=xstart(f);
                y(f)=ystart(f);
             else
                 x(f)=actions(linecursor,2);
                 y(f)=actions(linecursor,3);
             end
          end
      end
      fill([x(1), x(2), x(4), x(3)],[y(1), y(2), y(4), y(3)],'r');
   end
   
   %imwrite(image, outfilename,'tif');

end